home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Libris Britannia 4
/
science library(b).zip
/
science library(b)
/
CUGUK
/
PROG_TOO
/
C013.ZIP
/
TOUCH.C
< prev
next >
Wrap
Text File
|
1990-01-19
|
2KB
|
74 lines
/********************************************************************
* C Users Group (U.K) C Source Code Library File CUGLIB.013 *
* Inquiries to: M. Houston, 36 Whetstone Clo. Farquhar Rd. *
* Edgbaston, Birmingham B15 2QN ENGLAND *
********************************************************************
* File name: touch.c
* Program name:touch
* Source of file: Ron Wellstead
* Purpose: An MS-DOS copy of the UNIX utility of the same name.
* Changes: <who what when & why major changes have been made>
********************************************************************/
/*
*
* @(#) touch.c 1.2 87/07/27
*
* UNIX style touch utility for dos
*
* copyright (c) 1987 Ron Wellsted.
* This software is provided on the understanding that it is
* NOT to be used for commercial gain. It may be freely distributed
* in source or object form among amateur and hobby computer users ONLY!
*
* sets the modification time of file(s) to the current time.
* usage: touch files -c files
* any file names given after the -c switch will be created if not present
* written for Microsoft C, link with setargv.obj to expand wildcards
*/
#include <stdio.h>
#include <stdlib.h>
#include <errno.h>
char what[]="@(#) touch VR 1.0.0 15 Jul 1987";
#define TRUE 1
#define FALSE 0
extern int errno;
FILE *stream;
main(argc,argv)
int argc;
char *argv[];
{
char *ptr;
int i,create=FALSE;
if (argc<2) {
printf("Usage : touch filespec... [-c filespec...]\n");
exit();
}
for (i=1;i<argc;i++) {
ptr=argv[i];
if ((*ptr=='-')||(*ptr=='/')) {
++ptr;
if (tolower(*ptr)=='c') create=TRUE;
continue;
}
printf("%s",ptr);
if (utime(ptr,NULL)==-1) {
if ((errno==ENOENT)&&(create)) {
if ((stream=fopen(ptr,"w"))==NULL)
perror(" : Not created ");
else fclose(stream);
printf(" : created\n");
continue;
}
perror(" : Not modified ");
continue;
}
printf(" : modified\n");
}
}